package com.sudo.common.utils;

import org.springframework.core.LocalVariableTableParameterNameDiscoverer;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class ParamUtil {

    public static Map<String,Object> getParamMap(Method method, Object[] args){
        LocalVariableTableParameterNameDiscoverer u = new LocalVariableTableParameterNameDiscoverer();
        String[] paramNames = u.getParameterNames(method);
        Map<String, Object> objectMap = new HashMap<>();
        if (args != null && paramNames != null){
            for (int i = 0; i < args.length; i++) {
                objectMap.put(paramNames[i], args[i]);
            }
        }
        return objectMap;
    }
}
